package 反射.T6;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.List;

public class T6 {

    public static void main(String[] args) throws ClassNotFoundException, IOException, IllegalAccessException, InstantiationException, NoSuchFieldException {

        List<String> lines = FileUtils.readLines(new File("反射/T6/data1.txt"),"UTF-8");
        List<String> list = FileUtils.readLines(new File("反射/T6/data1.txt"),"UTF-8");

        Class<?> aClass = Class.forName(lines.get(0));
        Object obj = aClass.newInstance();

        for (String s : list) {
            String[] ss = s.split("=");
            Field df = aClass.getDeclaredField(ss[0]);
            df.setAccessible(true);
            if (ss[0].equals("age")){
                df.set(obj,Integer.parseInt(ss[1]));
            }else {
                df.set(obj,ss[1]);
            }
        }
        System.out.println(obj);

    }
}
